import { ElNotification } from 'element-plus';
export function responseSuccessFunc({ response, config }) {
	$JiessLoading.response(config.mainURL, config.method);
	if (response.code === 200) {
		return response.data;
	} else {
		errorHandler(response);
		return Promise.reject(response);
	}

	function errorHandler(res) {
		if (res.code === '401') {
			// token校验失败
		} else {
			ElNotification({ message: res.msg, type: 'error' });
		}
	}
}

export function responseErrorFunc({ responseText, config }) {
	$JiessLoading.response(config.mainURL, config.method);
	ElNotification({ message: responseText, type: 'error' });
}

export function requestFunc(config) {
	$JiessLoading.request(config.mainURL, config.method);
	return config;
}